home *** CD-ROM | disk | FTP | other *** search
- Unit WinCrypt;
-
- {
- WINCRYPT.PAS conversion from C header file WINCRPYT.C
- Jani JΣrvinen 1998.
- }
-
- Interface
-
- Uses Windows;
-
- Function GetAlgClass(AClass : Integer) : Integer;
- Function GetAlgType(AType : Integer) : Integer;
- Function GetAlgSID(SID : Integer) : Integer;
-
- Function RCryptSucceeded(rt : Boolean) : Boolean;
- Function RCryptFailed(rt : Boolean) : Boolean;
-
- { Algorithm classes }
- Const
- AlgClassAny = 0;
- AlgClassSignature = 1 shl 13;
- AlgClassMsgEncrypt = 2 shl 13;
- AlgClassDataEncrypt = 3 shl 13;
- AlgClassHash = 4 shl 13;
- AlgClassKeyExchange = 5 shl 13;
-
- { Algorithm types }
- AlgTypeAny = 0;
- AlgTypeDSS = 1 shl 9;
- AlgTypeRSA = 2 shl 9;
- AlgTypeBlock = 3 shl 9;
- AlgTypeStream = 4 shl 9;
-
- { Generic sub-ids }
- AlgSIDAny = 0;
-
- { Some RSA sub-ids }
- AlgSIDRSAAny = 0;
- AlgSIDRSAPKCS = 1;
- AlgSIDRSAMSAtWork = 2;
- AlgSIDRSAEntrust = 3;
- AlgSIDRSAPGP = 4;
-
- { Some DSS sub-ids }
- AlgSIDDSSAny = 0;
- AlgSIDDSSPKCS = 1;
- AlgSIDDSSDMS = 2;
-
- { Block cipher sub ids }
- AlgSIDDES = 1; { DES subids }
- AlgSID3DES = 3;
- AlgSIDDESX = 4;
- AlgSIDIDEA = 5;
- AlgSIDCAST = 6;
- AlgSIDSaferSK64 = 7;
- ALDSIDSaferSK128 = 8;
- { KP_MODE }
- CryptModeCBCI = 6; { ANSI CBC Interleaved }
- CryptModeCFBP = 7; { ANSI CFB Pipelined }
- CryptModeOFBP = 8; { ANSI OFB Pipelined }
- CryptModeCBCOFM = 9; { ANSI CBC + OF Masking }
- CryptModeCBCOFMI = 10; { ANSI CBC + OFM Interleaved }
-
- { RC2 sub-ids }
- AlgSIDRC2 = 2;
-
- { Stream cipher sub-ids }
- AlgSIDRC4 = 1;
- AlgSIDSEAL = 2;
-
- { Hash sub ids }
- AlgSIDMD2 = 1;
- AlgSIDMD4 = 2;
- AlgSIDMD5 = 3;
- AlgSIDSHA = 4;
- AlgSIDMAC = 5;
- AlgSIDRIPEMD = 6;
- AlgSIDRIPEMD160 = 7;
- AlgSIDSSL3SHAMD5 = 8;
-
- { Our silly example sub-id }
- AlgSIDExample = 80;
-
- { (Class) algorithm identifier definitions }
- CAlgMD2 = (AlgClassHash Or AlgTypeAny Or AlgSIDMD2);
- CAlgMD4 = (AlgClassHash Or AlgTypeAny Or AlgSIDMD4);
- CAlgMD5 = (AlgClassHash Or AlgTypeAny Or AlgSIDMD5);
- CAlgSHA = (AlgClassHash Or AlgTypeAny Or AlgSIDSHA);
- CAlgMAC = (AlgClassHash Or AlgTypeAny Or AlgSIDMAC);
- CAlgRSASign = (AlgClassSignature Or AlgTypeRSA Or AlgSIDRSAAny);
- CAlgDSSSign = (AlgClassSignature Or AlgTypeDSS Or AlgSIDDSSAny);
- CAlgRSAKeyX = (AlgClassKeyExchange Or AlgTypeRSA Or AlgSIDRSAAny);
- CAlgDES = (AlgClassDataEncrypt Or AlgTypeBlock Or AlgSIDDES);
- CAlgRC2 = (AlgClassDataEncrypt Or AlgTypeBlock Or AlgSIDRC2);
- CAlgRC4 = (AlgClassDataEncrypt Or AlgTypeStream Or AlgSIDRC4);
- CAlgSeal = (AlgClassDataEncrypt Or AlgTypeStream Or AlgSIDSeal);
-
- Type
- PVTableProvStruc = ^TVTableProvStruc;
- TVTableProvStruc = Record
- Version : Integer;
- FuncVerifyImage : TFarProc;
- FuncReturnhWnd : TFarProc;
- End;
-
- TCryptProv = Integer;
- TCryptKey = Integer;
- TCryptHash = Integer;
- TAlgId = Integer;
- PCryptProv = ^TCryptProv;
- PCryptKey = ^TCryptKey;
- PCryptHash = ^TCryptHash;
- PAlgId = ^TAlgId;
-
- Const
- { dwFlags definitions for CryptAquireContext }
- CryptVerfiyContext = $F0000000;
- CryptNewKeySet = 8;
- CryptDeleteKeySet = 16;
-
- { dwFlag definitions for CryptGenKey }
- CryptExportable = 1;
- CryptUserProtected = 2;
- CryptCreateSalt = 4;
- CryptUpdateKey = 8;
-
- { exported key blob definitions }
- SimpleBLOB = 1;
- PublicKeyBLOB = 6;
- PricateKeyBLOB = 7;
-
- ATKeyExchange = 1;
- ATSignature = 2;
-
- CryptUserData = 1;
-
- { dwParam }
- KPIV = 1; { Initialization vector }
- KPSalt = 2; { Salt value }
- KPPadding = 3; { Padding values }
- KPMode = 4; { Mode of the cipher }
- KPModeBits = 5; { Number of bits to feedback }
- KPPermissions = 6; { Key permissions DWORD }
- KPAlgID = 7; { Key algorithm }
- KPBlockLen = 8; { Block size of the cipher }
-
- { KP_PADDING }
- PKCS5Padding = 1; { PKCS 5 (sec 6.2) padding method }
-
- { KP_MODE }
- CryptModeCBC = 1; { Cipher block chaining }
- CryptModeECB = 2; { Electronic code book }
- CryptModeOFB = 3; { Output feedback mode }
- CryptModeCFB = 4; { Cipher feedback mode }
- CryptModeCTS = 5; { Ciphertext stealing mode }
-
- { KP_PERMISSIONS }
- Crypt_Encrypt = 1; { Allow encryption }
- Crypt_Decrypt = 2; { Allow decryption }
- CryptExport = 4; { Allow key to be exported }
- CryptRead = 8; { Allow parameters to be read }
- CryptWWrite = 16; { Allow parameters to be set }
- CryptMAC = 32; { Allow MACs to be used with key }
-
- HPAlgID = 1; { Hash algorithm }
- HPHashVal = 2; { Hash value }
- HPHashSize = 4; { Hash value size }
-
- CryptFailed = False;
- CryptSucceed = True;
-
- Const
- { CryptGetProvParam }
- PPEnumAlgs = 1;
- PPEnumContainers = 2;
- PPImpType = 3;
- PPName = 4;
- PPVersion = 5;
- PPContainer = 6;
-
- CryptFirst = 1;
- CryptNext = 2;
-
- CryptImplHardware = 1;
- CryptImplSoftware = 2;
- CryptImplMixed = 3;
- CryptImplUnknown = 4;
-
- { CryptSetProvParam }
- PPClienthWnd = 1;
-
- ProvRSAFull = 1;
- ProvRSASIG = 2;
- ProvDSS = 3;
- ProvFortezza = 4;
- ProvMSExchange = 5;
- ProvSSL = 6;
-
- { STT defined Providers }
- ProvSTTMER = 7;
- ProvSTTACQ = 8;
- ProvSTTBRND = 9;
- ProvSTTRoot = 10;
- ProvSTTISS = 11;
-
- ProvText = 'Microsoft Base Cryptographic Provider v1.0';
- MSDefProvA : PAnsiChar = ProvText;
- MSDefProvW : PWideChar = ProvText;
- MSDefProv : PAnsiChar = ProvText;
-
- MaxUIDLen = 64;
- CurBLOBVersion = 2;
-
- Type
- TProvEnumAlgs = Record
- aiAlgid : TAlgID;
- dwBitLen : Integer;
- dwNameLen : Integer;
- szName : Array[0..19] of Char;
- End;
-
- TPublicKeyStruc = Record
- bType : Byte;
- bVersion : Byte;
- Reserved : Word;
- aiKeyAlg : TAlgID;
- End;
-
- TRSAPubKey = Record
- Magic : Integer; { Has to be RSA1 }
- BitLen : Integer; { # of bits in modulus }
- PubExp : Integer; { public exponent }
- End; { modulus data follows }
-
- Function CryptAcquireContextA(phProv : PCryptProv;
- pszContainer,pszProvider : PChar;
- dwProvType,dwFlags : Integer) : Bool; StdCall;
-
- Function CryptAcquireContextW(phProv : PCryptProv;
- pszContainer,pszProvider : PWideChar;
- dwProvType,dwFlags : Integer) : Bool; StdCall;
-
- Function CryptAcquireContext(phProv : PCryptProv;
- pszContainer,pszProvider : PChar;
- dwProvType,dwFlags : Integer) : Bool; StdCall;
-
- Function CryptReleaseContext(hProv : TCryptProv; dwFlags : Integer) : Bool; StdCall;
-
- Function CryptGenKey(hProv : TCryptProv; Algid : TAlgID; dwFlags : Integer;
- phKey : PCryptKey) : Bool; StdCall;
-
- Function CryptDeriveKey(hProv : TCryptProv;
- Algid : TAlgID;
- hBaseData : TCryptHash;
- dwFlags : Integer;
- phKey : PCryptKey) : Bool; StdCall;
-
-
- Function CryptDestroyKey(hKey : TCryptKey) : Bool; StdCall;
-
- Function CryptSetKeyParam(hKey : TCryptKey;
- dwParam : Integer;
- pbData : Pointer;
- dwFlags : Integer) : Bool; StdCall;
-
- Function CryptGetKeyParam(hKey : TCryptKey;
- dwParam : Integer;
- pbData : Pointer;
- Var pdwDataLen : Integer;
- dwFlags : Integer) : Bool; StdCall;
-
- Function CryptSetHashParam(hHash : TCryptHash;
- dwParam : Integer;
- pbData : Pointer;
- dwFlags : Integer) : Bool; StdCall;
-
- Function CryptGetHashParam(hHash : TCryptHash;
- dwParam : Integer;
- pbData : Pointer;
- Var pdwDataLen : Integer;
- dwFlags : Integer) : Bool; StdCall;
-
- Function CryptSetProvParam(hProv : TCryptProv;
- dwParam : Integer;
- pbData : Pointer;
- dwFlags : Integer) : Bool; StdCall;
-
- Function CryptGetProvParam(hProv : TCryptProv;
- dwParam : Integer;
- pbData : Pointer;
- Var pdwDataLen : Integer;
- dwFlags : Integer) : Bool; StdCall;
-
- Function CryptGenRandom(hProv : TCryptProv;
- dwLen : Integer;
- pbBuffer : Pointer) : Bool; StdCall;
-
- Function CryptGetUserKey(hProv : TCryptProv;
- dwKeySpec : Integer;
- phUserKey : PCryptKey) : Bool; StdCall;
-
- Function CryptExportKey(hKey,hExpKey : TCryptKey;
- dwBlobType,dwFlags : Integer;
- pbData : Pointer;
- Var pdwDataLen : Integer) : Bool; StdCall;
-
- Function CryptImportKey(hProv : TCryptProv;
- Const pbData : Pointer;
- dwDataLen : Integer;
- hPubKey : TCryptKey;
- dwFlags : Integer;
- phKey : PCryptKey) : Bool; StdCall;
-
- Function CryptEncrypt(hKey : TCryptKey;
- hHash : TCryptHash;
- Final : Bool;
- dwFlags : Integer;
- pbData : Pointer;
- Var pdwDataLen : Integer;
- dwBufLen : Integer) : Bool; StdCall;
-
- Function CryptDecrypt(hKey : TCryptKey;
- hHash : TCryptHash;
- Final : Bool;
- dwFlags : Integer;
- pbData : Pointer;
- Var pdwDataLen : Integer) : Bool; StdCall;
-
- Function CryptCreateHash(hProv : TCryptProv;
- Algid : TAlgID;
- hKey : TCryptKey;
- dwFlags : Integer;
- phHash : PCryptHash) : Bool; StdCall;
-
- Function CryptHashData(hHash : TCryptHash;
- Const pbData : Pointer;
- dwDataLen,dwFlags : Integer) : Bool; StdCall;
-
- Function CryptHashSessionKey(hHash : TCryptHash;
- hKey : TCryptKey;
- dwFlags : Integer) : Bool; StdCall;
-
- Function CryptDestroyHash(hHash : TCryptHash) : Bool; StdCall;
-
- Function CryptSignHashA(hHash : TCryptHash;
- dwKeySpec : Integer;
- sDescription : PChar;
- dwFlags : Integer;
- pbSignature : Pointer;
- Var pdwSigLen : Integer) : Bool; StdCall;
-
- Function CryptSignHashW(hHash : TCryptHash;
- dwKeySpec : Integer;
- sDescription : PWideChar;
- dwFlags : Integer;
- pbSignature : Pointer;
- pdwSigLen : Integer) : Bool; StdCall;
-
- Function CryptSignHash(hHash : TCryptHash;
- dwKeySpec : Integer;
- sDescription : PChar;
- dwFlags : Integer;
- pbSignature : Pointer;
- Var pdwSigLen : Integer) : Bool; StdCall;
-
- Function CryptVerifySignatureA(hHash : TCryptHash;
- Const pbSignature : Pointer;
- dwSigLen : Integer;
- hPubKey : TCryptKey;
- sDescription : PChar;
- dwFlags : Integer) : Bool; StdCall;
-
- Function CryptVerifySignatureW(hHash : TCryptHash;
- Const pbSignature : Pointer;
- dwSigLen : Integer;
- hPubKey : TCryptKey;
- sDescription : PWideChar;
- dwFlags : Integer) : Bool; StdCall;
-
- Function CryptVerifySignature(hHash : TCryptHash;
- Const pbSignature : Pointer;
- dwSigLen : Integer;
- hPubKey : TCryptKey;
- sDescription : PChar;
- dwFlags : Integer) : Bool; StdCall;
-
- Function CryptSetProviderA(pszProvName : PChar;
- dwProvType : Integer) : Bool; StdCall;
-
- Function CryptSetProviderW(pszProvName : PWideChar;
- dwProvType : Integer) : Bool; StdCall;
-
- Function CryptSetProvider(pszProvName : PChar;
- dwProvType : Integer) : Bool; StdCall;
-
- Implementation
-
- { Algorithm IDs and Flags }
-
- { Alg_ID crackers }
- Function GetAlgClass(AClass : Integer) : Integer;
- Begin
- Result := (AClass And (7 shl 13));
- End;
-
- Function GetAlgType(AType : Integer) : Integer;
- Begin
- Result := (AType And (15 shl 9));
- End;
-
- Function GetAlgSID(SID : Integer) : Integer;
- Begin
- Result := (SID And 511);
- End;
-
- Function RCryptSucceeded(rt : Boolean) : Boolean;
- Begin
- Result := (rt = CryptSucceed);
- End;
-
- Function RCryptFailed(rt : Boolean) : Boolean;
- Begin
- Result := (rt = CryptFailed);
- End;
-
- Function CryptAcquireContextA; External advapi32 Name 'CryptAcquireContextA';
- Function CryptAcquireContextW; External advapi32 Name 'CryptAcquireContextW';
- Function CryptAcquireContext; External advapi32 Name 'CryptAcquireContextA';
- Function CryptReleaseContext; External advapi32 Name 'CryptReleaseContext';
- Function CryptGenKey; External advapi32 Name 'CryptGenKey';
- Function CryptDeriveKey; External advapi32 Name 'CryptDeriveKey';
- Function CryptDestroyKey; External advapi32 Name 'CryptDestroyKey';
- Function CryptSetKeyParam; External advapi32 Name 'CryptSetKeyParam';
- Function CryptGetKeyParam; External advapi32 Name 'CryptGetKeyParam';
- Function CryptSetHashParam; External advapi32 Name 'CryptSetHashParam';
- Function CryptGetHashParam; External advapi32 Name 'CryptGetHashParam';
- Function CryptSetProvParam; External advapi32 Name 'CryptSetProvParam';
- Function CryptGetProvParam; External advapi32 Name 'CryptGetProvParam';
- Function CryptGenRandom; External advapi32 Name 'CryptGenRandom';
- Function CryptGetUserKey; External advapi32 Name 'CryptGetUserKey';
- Function CryptExportKey; External advapi32 Name 'CryptExportKey';
- Function CryptImportKey; External advapi32 Name 'CryptImportKey';
- Function CryptEncrypt; External advapi32 Name 'CryptEncrypt';
- Function CryptDecrypt; External advapi32 Name 'CryptDecrypt';
- Function CryptCreateHash; External advapi32 Name 'CryptCreateHash';
- Function CryptHashData; External advapi32 Name 'CryptHashData';
- Function CryptHashSessionKey; External advapi32 Name 'CryptHashSessionKey';
- Function CryptDestroyHash; External advapi32 Name 'CryptDestroyHash';
- Function CryptSignHashA; External advapi32 Name 'CryptSignHashA';
- Function CryptSignHashW; External advapi32 Name 'CryptSignHashW';
- Function CryptSignHash; External advapi32 Name 'CryptSignHashA';
- Function CryptVerifySignatureA; External advapi32 Name 'CryptVerifySignatureA';
- Function CryptVerifySignatureW; External advapi32 Name 'CryptVerifySignatureW';
- Function CryptVerifySignature; External advapi32 Name 'CryptVerifySignatureA';
- Function CryptSetProviderA; External advapi32 Name 'CryptSetProviderA';
- Function CryptSetProviderW; External advapi32 Name 'CryptSetProviderW';
- Function CryptSetProvider; External advapi32 Name 'CryptSetProviderA';
-
- End.
-